/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1BA2C0C8-01AF-4D3C-B45A-1A7F48B0C940",variableType:4}
 */
var gAccionEstado = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"28C70493-7565-443B-8C6A-45520A3A423C",variableType:4}
 */
var gUsuario = null;

/**
 * Calculate the row background color.
 *
 * @param {Number} index row index
 * @param {Boolean} selected is the row selected
 * @param {String} elementType element type (not supported in webclient)
 * @param {String} dataProviderID element data provider (not supported in webclient)
 * @param {String} formName form name
 * @param {JSRecord<db:/contador_hs/temas>} record selected record
 * @param {Boolean} edited is the record edited
 *
 * @returns {String}
 *
 * @properties={typeid:24,uuid:"DB8E43C2-45F4-437F-91B7-6B98B311E20B"}
 */
function rowBGColorTemas(index, selected, elementType, dataProviderID, formName, record, edited) {
	if (record.prioridad == 3)
		return '#ff8080';
	else
	{
		var $hoy = new Date()
		$hoy.setHours(0,0,0,0)
		if (record.fecha_proxima_accion == $hoy)
			return '#ffff80'
		else
			return '#f0f0f0';		
	}
}

/**
 * @properties={typeid:24,uuid:"978149CA-E634-4D00-BBF3-FEAB6CD5EA45"}
 */
function irAlMenu() {
	forms.temas_tbl.controller.show()
}

/**
 * @param {Number} $tema_id
 * 
 * @param {Number} [$respuesta_id]
 *
 * @properties={typeid:24,uuid:"64182602-8536-47B1-A39A-0C5B792C2070"}
 */
function llenarFechaProxima($tema_id, $respuesta_id)
{
	var $hoy = application.getServerTimeStamp()
	$hoy.setHours(0,0,0,0)
	var query = 'SELECT MIN(fecha_accion) FROM respuestas '+
				'WHERE fecha_accion >= ? and tema_id = ? and estado = 1 '
	var args = [$hoy, $tema_id]
	if ($respuesta_id)
	{
		query += 'and respuesta_id != ?'
		args[2] = $respuesta_id	
	}
	query += 'GROUP BY tema_id'
	
	var $ds = databaseManager.getDataSetByQuery('contador_hs',query,args,1)
	return $ds.getValue(1,1)
}
/**
 * Callback method for when solution is opened.
 *
 * @properties={typeid:24,uuid:"588AC762-0EF8-4D2C-AC67-271D1B64DE27"}
 */
function onSolutionOpen() {
	var query = 'select usuario_id from usuarios where usuario = ?'
	var args = [security.getUserName()]
	var max = -1
	
	var ds = databaseManager.getDataSetByQuery('fwk_navigation_infocom',query,args,max)
	
	if (ds.getMaxRowIndex() == 0)
	{
		globals.DIALOGS.showErrorDialog('Aviso','Problema con usuarios','OK')
		security.logout()
	}
	else
	{
		globals.gUsuario 			= ds.getValue(1,1)
		forms.temas_tbl.fOperador 	= globals.gUsuario
		
	}
}
